package com.youxin.busfoundation.bean;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.youxin.foundation.utils.JsonUtils;

/**
 * 信息输出通用接口
 * @author yingde.cao
 *
 * @param <T>
 */
public class ResponseGeneric<T extends Object>  {

	//private static final long serialVersionUID = 124133254345L;

	private int code=BusinessMessages.SUCCESS_CODE ;

	private String msg = BusinessMessages.SUCCESS_MESSAGE;
	
	@JsonProperty("tracking_id")
	private long trackingId;
	
	

	private long timestamp=System.currentTimeMillis();

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	public ResponseGeneric() {		
	}

	public ResponseGeneric(T data) {
		this.data = data;
	}

	public ResponseGeneric(ResponseMessage responseMessage) {
		this(responseMessage, null);
	}
	
	public ResponseGeneric(ResponseMessage responseMessage,T data) {
		this.code = responseMessage.getCode();
		this.msg = responseMessage.getMsg();
		this.data = data;
	}
	

	private T data;

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
	
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public long getTrackingId() {
		return trackingId;
	}

	public void setTrackingId(long trackingId) {
		this.trackingId = trackingId;
	}

	/**
	 * 是否成功的状态
	 * @return
	 */
	public boolean success() {
		return this.code == BusinessMessages.SYSTEM_OK.getCode();
	}
	
	public long getResponseTime()
	{
		return System.currentTimeMillis();
	}
	
	@Override
	public String toString() {
		return JsonUtils.objectToFasterxmlJsonString(this);
	}

}
